home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dirname / dirname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-12  |  1.2 KB  |  48 lines

  1. /*
  2.  * dirname.c --
  3.  *
  4.  *  Dirname treats its first argument as a filename, and returns the
  5.  *  name of the directory prortion.  It strips off anything following
  6.  *  the last '/'.  The resulting string is printed to the standard output.
  7.  *
  8.  * Copyright 1988 Regents of the University of California
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifndef lint
  19. static char rcsid[] = "$Header: /a/newcmds/basename/RCS/basename.c,v 1.2 88/12/13 11:05:07 rab Exp $";
  20. #endif
  21.  
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25.  
  26. void
  27. main(argc, argv)
  28.     int argc;
  29.     char **argv;
  30. {
  31.     char *dirname, *slash;
  32.     int len;
  33.  
  34.     if (argc < 2) {
  35.     fputs("usage: dirname string\n", stderr);
  36.     exit(EXIT_FAILURE);
  37.     }
  38.     dirname = argv[1];
  39.     if ((slash = strrchr(dirname, '/')) == NULL) {
  40.     dirname = ".";
  41.     } else {
  42.     *slash = '\0';
  43.     }
  44.     puts(dirname);
  45.     exit(EXIT_SUCCESS);
  46. }
  47.  
  48.